package com.human.server.controller;


import com.human.server.entity.Users;
import com.human.server.model.R;
import com.human.server.model.request.UserRequest;
import com.human.server.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户基础信息表 前端控制器
 * </p>
 *
 * @author zooy
 * @since 2025-08-26
 */
@RestController
@RequestMapping("/human/user")
public class UserController {

    @Autowired
    private UsersServiceImpl userService;

    @PostMapping("/login")
    public R login(@RequestBody Users user) {

        return userService.loginValid(user);
    }

    /**
     * 查询
     */
    @PostMapping("/query")
    public R query(@RequestBody Users user) {
        return R.success(userService.getById(user.getId()));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public R add(@RequestBody Users user) {

        userService.save(user);
        return R.success();
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    public R update(@RequestBody Users user) {
        return R.success(userService.updateById(user));
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Users user) {
        return R.success(userService.removeById(user.getId()));
    }

    /**
     * 分页查询
     */
    @PostMapping("/page")
    public R page(@RequestBody UserRequest userRequest) {

        return R.success(userService.page(userRequest));
    }

    /**
     * resetPassword
     */
    @PostMapping("/resetPassword")
    public R resetPassword(@RequestBody Users user) {
        userService.resetPassword(user);
        return R.success();
    }

}
